<template>
	<view class="content">
		<uni-list>
			<uni-list-item v-for="(item,index) in lst" :key="index" @click="go_detail(item.itemid)" :title="item.title"></uni-list-item>
		</uni-list>
		<uni-load-more :status="more"></uni-load-more>
	</view>
</template>

<script>
	import config from '../../lib/config.js'
	import uniList from "@/components/uni-list/uni-list.vue"
	import uniListItem from "@/components/uni-list-item/uni-list-item.vue"
	import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue"
	export default {
		components: {
			uniList,
			uniListItem,
			uniLoadMore
		},
		data() {
			return {
				page: 1,
				total_page: 1,
				lst: [],
				more: "loading",
			}
		},
		methods: {
			load_data: function(type='load_more') {
				if (type=='load_more' && (this.page > this.total_page)) {
					this.page=this.total_page;
					this.more = "noMore";
					uni.hideNavigationBarLoading();
					return;
				}
				
				this.more='loading';
				
				uni.request({
					method: 'GET',
					url: config.api_url,
					data: {
						action: 'lst',
						page: this.page
					},
					success: (res) => {
						console.log(res);
						let d = res.data;
						if(type=='load_more'){
							this.lst = this.lst.concat(d.data.lst);
						}else{
							this.lst = d.data.lst;
						}
						this.total_page = d.data.total_page;
						
						this.more='more';
						
						if(type=='load_more'){
							
						}else{
							uni.stopPullDownRefresh();
						}
						
					},
				})
			},
			load_more: function() {
				console.log('load more...');
				this.page++;
				this.load_data();
			},
			go_detail: function(itemid) {
				console.log(itemid);
				uni.navigateTo({
					url: '../detail/detail?itemid=' + itemid
				});
			}
		},
		created: function() {
			this.load_data();
		},
		onPullDownRefresh:function(){
			this.page=1;
			this.load_data('refresh');
		},
		onReachBottom:function(){
			this.load_more();
		}
	}
</script>

<style>

</style>
